package me.lc.linklink.sprite;

import java.util.Random;

import me.lc.linklink.core.GameSystem;

import com.wiyun.engine.actions.Action.Callback;
import com.wiyun.engine.actions.IntervalAction;
import com.wiyun.engine.actions.ScaleTo;
import com.wiyun.engine.nodes.AtlasLabel;
import com.wiyun.engine.nodes.Node;
import com.wiyun.engine.nodes.Sprite;
import com.wiyun.engine.types.WYColor3B;
import com.wiyun.engine.utils.ResolutionIndependent;

/**
 * 四角随机出现的combo
 * 
 * @author Administrator
 * 
 */
public class ComboBlock extends Node {
	private Sprite sptCombo;
	private AtlasLabel labelCombo;
	ComboCallback callback;

	Random rConner = new Random();

	public ComboBlock() {
		sptCombo = Sprite.make(GameSystem.comboTex);
		// sptCombo.setAnchorPercent(0, 0);
		// sptCombo.setPosition(0, 0);
		addChild(sptCombo);

		labelCombo = AtlasLabel.make("00", GameSystem.numberTex,
				GameSystem.charMap);
		labelCombo.setColor(WYColor3B.make(200, 200, 0));
		// labelCombo.setAnchorPercent(0, 0);
		labelCombo.setPosition(0, ResolutionIndependent.resolveDp(30));
		addChild(labelCombo);
		this.setVisible(false);
		this.setTouchEnabled(false);
		callback = new ComboCallback();
	}

	public void showCombo(int combo) {
		float scaleToValue = 1f;
		int red = 200;
		if (combo > 5) {
			red = 220;
			scaleToValue = 1.1f;
		} else if (combo > 10) {
			red = 255;
			scaleToValue = 1.4f;
		}

		this.setPosition(GameSystem.Screen_Width / 2,
				GameSystem.Screen_Height / 2);
		labelCombo.setText(combo + "");
		labelCombo.setColor(WYColor3B.make(red, 200, 0));

		// 做动画
		this.setVisible(true);
		IntervalAction showAction = (IntervalAction) ScaleTo.make(0.4f, 0.6f,
				scaleToValue).autoRelease();
		showAction.setCallback(callback);
		this.runAction(showAction);

	}

	/**
	 * 动画回调
	 * 
	 * @author Administrator
	 * 
	 */
	class ComboCallback implements Callback {

		@Override
		public void onStart(int arg0) {
			// TODO Auto-generated method stub

		}

		@Override
		public void onStop(int arg0) {
			ComboBlock.this.setVisible(false);
			ComboBlock.this.setScale(0.4f);
		}

		@Override
		public void onUpdate(int arg0, float arg1) {
			// TODO Auto-generated method stub

		}

	}
}
